using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using IGlobalist.Cms.Common;
using System.Collections.Generic;
using IGlobalist.Cms.Model;
using IGlobalist.Cms.Bll;

namespace IGlobalist.Cms.Admin.Control
{
    public partial class CategoryListTree : AdminBaseUserControl
    {
       
        #region Properties
        public string SelectedValue
        {
            get { return Convert.ToString(ViewState["_ClassID"]); }
            set { ViewState["_ClassID"] = value; }
        }
         #endregion      
       
        public event EventHandler TreeNodeClick;

        protected void Page_Load(object sender, EventArgs e)
        {
            //BindTree();
        }

        public IList<CmsClass> DataSource
        {
            set
            {
                ViewState["_classList"] = value;
            }
        }
        public override void DataBind()
        {
            IList<CmsClass> cList = (IList<CmsClass>)ViewState["_classList"];
            if (cList.Count > 0)
            {
                tvClass.Nodes.Clear();
                TreeNode root = new TreeNode("Class List", "Class List");
                foreach (CmsClass c in cList)
                {
                    TreeNode parent = new TreeNode(c.Name, c.ID.ToString());
                    parent.NavigateUrl = "javascript:void(0)";
                    IList<IContentCategory> categoryList = CategoryController.GetCategoryList(c.ID);
                    foreach (Category cc in categoryList)
                    {
                        parent.ChildNodes.Add(new TreeNode(cc.Name, cc.ID.ToString()));
                    }                    
                }
                tvClass.Nodes.Add(root);
            }        
        }      

        protected void tvClass_SelectedNodeChanged(object sender, EventArgs e)
        {
            if (TreeNodeClick != null && tvClass.SelectedNode.Depth ==2)            
            {
                this.SelectedValue = tvClass.SelectedValue;
                TreeNodeClick(this, e);
            }
        }
    }
}